#filter-out是将 src/main.cpp 排除掉
cpp_srcs := $(filter-out src/main.cpp,$(shell find src -name *.cpp))
cpp_objs := $(patsubst src/%.cpp,objs/%.o,$(cpp_srcs))

so_objs := $(filter-out objs/main.o,$(cpp_objs))


include_dirs := /home/sx/linux/5-makefike/include
library_dirs := /home/sx/linux/5-makefike/lib

linking_libs := ddd

I_options := $(include_dirs:%=-I%)
l_options := $(linking_libs:%=-l%)
L_options := $(library_dirs:%=-L%)
r_options := $(library_dirs:%=-Wl,-rpath=%)

compile_options := -g -O3 -w -fPIC $(I_options)
# rpath : 表示程序运行时库的搜索路径 run_path
# -Wl 是编译器（如 GCC）传递给链接器（ld）的参数标记，用于告诉编译器后续参数应直接传递给链接
linking_options := $(l_options) $(L_options) $(r_options)

objs/%.o : src/%.cpp
	@mkdir -p $(dir $@)
	@g++ -c $^ -o $@ $(compile_options)

compile : $(cpp_objs)

lib/libddd.so : $(so_objs)
	@mkdir -p $(dir $@)
	@g++ -shared $^ -o $@

dynamic : lib/libddd.so

workspace/exec : objs/main.o compile dynamic
	@mkdir -p $(dir $@)
	@g++ $< -o $@ $(linking_options)


run : workspace/exec
	@./$<

debug :
	@echo $(so_objs)

clean :
	rm -rf objs workspace lib

.PHONY:debug clean run compile dynamic

